/**
 * @Author：ming
 * @Date：2023/10/6 8:21 PM
 * @Filename：Lc128
 */

import java.util.Arrays;

/**
 * @author ming
 */
public class Lc128 {
        public int longestConsecutive(int[] nums) {
            if(nums.length==0){
                return 0;
            }
            if(nums.length==1){
                return 1;
            }
            Arrays.sort(nums);
            int count =1;
            int max =1;
            for (int i = 1; i < nums.length; i++) {
                if(nums[i]==nums[i-1]){
                    continue;
                } else if(nums[i]-nums[i-1]==1){
                    count++;
                    max = Math.max(count,max);
                }else {
                    count =1;
                }
            }
            return max;
        }

}
